/***************************************************************************
 *   Copyleft 2008-2009 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#ifndef __VLOGMACROS_H__
#define __VLOGMACROS_H__

#include <math.h>
#include <Math/vMathConstants.h>
#include "../Externals/vExternals.h"
#include "../Exceptions/vFatalException.h"

#ifdef V_DEBUG
	#define LOGS_DEBUG				Vendetta::vExternals::PtrLogs->Debug
	#define LOGS_ERROR				Vendetta::vExternals::PtrLogs->Error
	#define LOGS_INFO				Vendetta::vExternals::PtrLogs->Info
	#define LOGS_OPEN				Vendetta::vExternals::PtrLogs = new Vendetta::vLogger(); \
									Vendetta::vExternals::PtrLogs->Open();
	#define LOGS_OPEN_NO_CONSOLE	Vendetta::vExternals::PtrLogs = new Vendetta::vLogger(); \
									Vendetta::vExternals::PtrLogs->Open(false);
	#define LOGS_CLOSE				if (Vendetta::vExternals::PtrLogs) { \
										Vendetta::vExternals::PtrLogs->Close(); \
										delete Vendetta::vExternals::PtrLogs; \
										Vendetta::vExternals::PtrLogs = vNull; \
									}
	#ifdef V_DEBUG_EXCEPTION_CAST
		#define V_DO_CHECK			///< Enables / disables CHECK macro
	#endif

#else
	inline int StubElepsisFunctionForLog(...) { return 0; }
	static class StubClassForLog {
	public:
		inline void operator =(size_t) {}
	private:
		inline StubClassForLog &operator =(const StubClassForLog &)
		{ return *this; }
	} StubForLogObject;


	#define LOGS_DEBUG				StubForLogObject = sizeof StubElepsisFunctionForLog
	#define LOGS_ERROR				StubForLogObject = sizeof StubElepsisFunctionForLog
	#define LOGS_INFO				StubForLogObject = sizeof StubElepsisFunctionForLog
	#define LOGS_OPEN			
	#define LOGS_CLOSE	
#endif

#ifdef V_DO_CHECK
	/// Macro used to inform user what's wrong just before huge system crash;)
	#define V_CHECK(test)		\
	if (!(test)) {		\
		throw vFatalException("Fatal error caught \"%s\" (file: \"%s\" line: %d)", #test, __FILE__, __LINE__); \
	}
	#define V_CHECK_MSG(test, msgError)		\
	if (!(test)) {		\
		throw vFatalException("Fatal error caught \"%s\" (file: \"%s\" line: %d), \"%s\"", #test, __FILE__, __LINE__, #msgError); \
	}
#else
#define V_CHECK(test)
#define V_CHECK(test, msgError)
#endif

#endif // __VLOGMACROS_H__